/******************************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Ltd. 		              */
/*																              */
/*	NAME	  = t__sqlserver_bigint_add.c						              */
/*	NOTE	  = 												              */
/*	DATE	  = 2014/11/25 by geyh								              */
/******************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <CUnit/Basic.h>
#include <CUnit/CUnit.h>

#include "apmtest_cunit.h"
#include "../test_db2_comm.h"
#include <db2/db2_core.h>
#include <db2/db2_comm.h>
#include <db2/db2_param.h>
#include <db2/db2_cmd_obj.h>
#include <apmtest_comm.h>
#include <db2/config.h>

extern int __db2_parse_prpsqlstt(Conntrack *p_st_conn, Frhash_header *p_st_hash_report,
                                 L7session_db2_private *p_st_private, int i_whole_flg);

extern int __db2_parse_excsqlset(Conntrack *p_st_conn, Frhash_header *p_st_hash_report,
                                 L7session_db2_private *p_st_private, int i_whole_flg);


static int __suite_init(void)
{

    return 0;
}

static int __suite_cleanup(void)
{

    return 0;
}

static void __case1(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x53\xd0\x51\x00\x01\x00\x4d\x20\x14\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x41\x00\x05\x21\x0e\x01\x00\x30\xd0\x53\x00\x01\x00\x2a\x24\x14\x00\x00\x00\x00\x20\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x55\x53\x45\x52\x49\x44\x27\x61\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74\x6f\x72\x27\xff\x00\x2d\xd0\x53\x00\x01\x00\x27\x24\x14\x00\x00\x00\x00\x1d\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x57\x52\x4b\x53\x54\x4e\x4e\x41\x4d\x45\x27\x57\x69\x6e\x2d\x50\x43\x27\xff\x00\x5f\xd0\x43\x00\x01\x00\x59\x24\x14\x00\x00\x00\x00\x4f\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x41\x43\x43\x54\x4e\x47\x27\x4a\x43\x43\x30\x32\x31\x30\x30\x57\x69\x6e\x2d\x50\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x61\x64\x6d\x69\x6e\x69\x73\x74\x27\x2c\x58\x27\x30\x30\x27\xff",
                 271);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_EXCSQLSET);

    i_ret = __db2_parse_excsqlset(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->l_cursor_id, 65);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_req->p_st_command_pre->p_st_statement->p_sql,
                           "SET CLIENT USERID'administrator';SET CLIENT WRKSTNNAME'Win-PC';SET CLIENT ACCTNG'JCC02100Win-PC                                administ',X'00'");

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x58\xd0\x51\x00\x01\x00\x52\x20\x0d\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x02\x00\x05\x21\x16\xf1\x00\x05\x21\x46\x04",
                 88);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case2(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x53\xd0\x51\x00\x01\x00\x4d\x20\x14\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x41\x00\x05\x21\x0e\x01\x00\x30\xd0\x53\x00\x01\x00\x2a\x24\x14\x00\x00\x00\x00\x20\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x55\x53\x45\x52\x49\x44\x27\x61\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74\x6f\x72\x27\xff\x00\x2d\xd0\x53\x00\x01\x00\x27\x24\x14\x00\x00\x00\x00\x1d\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x57\x52\x4b\x53\x54\x4e\x4e\x41\x4d\x45\x27\x57\x69\x6e\x2d\x50\x43\x27\xff\x00\x5f\xd0\x43\x00\x01\x00\x59\x24\x14\x00\x00\x00\x00\x4f\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x41\x43\x43\x54\x4e\x47\x27\x4a\x43\x43\x30\x32\x31\x30\x30\x57\x69\x6e\x2d\x50\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x61\x64\x6d\x69\x6e\x69\x73\x74\x27\x2c\x58\x27\x30\x30\x27\xff",
                 271);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_EXCSQLSET);

    i_ret = __db2_parse_excsqlset(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->l_cursor_id, 65);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_req->p_st_command_pre->p_st_statement->p_sql,
                           "SET CLIENT USERID'administrator';SET CLIENT WRKSTNNAME'Win-PC';SET CLIENT ACCTNG'JCC02100Win-PC                                administ',X'00'");

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x58\xd0\x51\x00\x01\x00\x52\x20\x0d\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x02\x00\x05\x21\x16\xf1\x00\x05\x21\x46\x04",
                 88);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data, (char *) "\x00\x1e\xd0\x53\x00\x01", 6);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case3(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x53\xd0\x51\x00\x01\x00\x4d\x20\x14\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x41\x00\x05\x21\x0e\x01\x00\x30\xd0\x53\x00\x01\x00\x2a\x24\x14\x00\x00\x00\x00\x20\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x55\x53\x45\x52\x49\x44\x27\x61\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74\x6f\x72\x27\xff\x00\x2d\xd0\x53\x00\x01\x00\x27\x24\x14\x00\x00\x00\x00\x1d\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x57\x52\x4b\x53\x54\x4e\x4e\x41\x4d\x45\x27\x57\x69\x6e\x2d\x50\x43\x27\xff\x00\x5f\xd0\x43\x00\x01\x00\x59\x24\x14\x00\x00\x00\x00\x4f\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x41\x43\x43\x54\x4e\x47\x27\x4a\x43\x43\x30\x32\x31\x30\x30\x57\x69\x6e\x2d\x50\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x61\x64\x6d\x69\x6e\x69\x73\x74\x27\x2c\x58\x27\x30\x30\x27\xff",
                 271);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_EXCSQLSET);

    i_ret = __db2_parse_excsqlset(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->l_cursor_id, 65);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_req->p_st_command_pre->p_st_statement->p_sql,
                           "SET CLIENT USERID'administrator';SET CLIENT WRKSTNNAME'Win-PC';SET CLIENT ACCTNG'JCC02100Win-PC                                administ',X'00'");

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x58\xd0\x51\x00\x01\x00\x52\x20\x0d\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x02\x00\x05\x21\x16\xf1\x00\x05\x21\x46\x04",
                 88);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data, (char *) "\x00\x1e\xd0\x53\x00\x01", 6);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x18\x24\x50\x00\x00\x00\x00\x0e\x46\x4f\x52\x20\x52\x45\x41\x44\x20\x4f\x4e\x4c\x59\x20\xff",
                 24);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case4(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x53\xd0\x51\x00\x01\x00\x4d\x20\x14\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x41\x00\x05\x21\x0e\x01\x00\x30\xd0\x53\x00\x01\x00\x2a\x24\x14\x00\x00\x00\x00\x20\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x55\x53\x45\x52\x49\x44\x27\x61\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74\x6f\x72\x27\xff\x00\x2d\xd0\x53\x00\x01\x00\x27\x24\x14\x00\x00\x00\x00\x1d\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x57\x52\x4b\x53\x54\x4e\x4e\x41\x4d\x45\x27\x57\x69\x6e\x2d\x50\x43\x27\xff\x00\x5f\xd0\x43\x00\x01\x00\x59\x24\x14\x00\x00\x00\x00\x4f\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x41\x43\x43\x54\x4e\x47\x27\x4a\x43\x43\x30\x32\x31\x30\x30\x57\x69\x6e\x2d\x50\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x61\x64\x6d\x69\x6e\x69\x73\x74\x27\x2c\x58\x27\x30\x30\x27\xff",
                 271);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_EXCSQLSET);

    i_ret = __db2_parse_excsqlset(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->l_cursor_id, 65);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_req->p_st_command_pre->p_st_statement->p_sql,
                           "SET CLIENT USERID'administrator';SET CLIENT WRKSTNNAME'Win-PC';SET CLIENT ACCTNG'JCC02100Win-PC                                administ',X'00'");

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x58\xd0\x51\x00\x01\x00\x52\x20\x0d\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x02\x00\x05\x21\x16\xf1\x00\x05\x21\x46\x04",
                 88);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data, (char *) "\x00\x1e\xd0\x53\x00\x01", 6);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x18\x24\x50\x00\x00\x00\x00\x0e\x46\x4f\x52\x20\x52\x45\x41\x44\x20\x4f\x4e\x4c\x59\x20\xff",
                 24);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_TODO);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->l_cursor_id, 2);

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x49\xd0\x43\x00\x01\x00\x43\x24\x14\x00\x00\x00\x00\x39\x49\x4e\x53\x45\x52\x54\x20\x49\x4e\x54\x4f\x20\x73\x71\x6c\x6a\x2e\x61\x70\x6d\x5f\x74\x65\x73\x74\x31\x20\x28\x42\x49\x47\x49\x4e\x54\x2c\x49\x4e\x54\x45\x47\x45\x52\x29\x20\x76\x61\x6c\x75\x65\x73\x20\x28\x3f\x2c\x20\x3f\x29\xff",
                 73);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->l_cursor_id, 2);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_req->p_st_command_pre->p_st_statement->p_sql,
                           "INSERT INTO sqlj.apm_test1 (BIGINT,INTEGER) values (?, ?)");

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

static void __case5(void)
{
    int i_req_cp = 0;
    int i_ret = APM_L7_ANALYZE_SUCC;

    Conntrack *p_st_conn = NULL;
    CU_ASSERT_EQUAL(
            test_db2_create_ct(&p_st_conn, TEST_DB2_SRC_IP, TEST_DB2_DST_IP, TEST_DB2_SRC_PORT, TEST_DB2_DST_PORT),
            FR_SUCC);
    L7_session *p_st_session = frct_get_session(p_st_conn);
    L7session_db2_private *p_st_private = (L7session_db2_private *) frct_get_session_private(p_st_session);

    Frhash_header st_hash_report;
    CU_ASSERT_EQUAL(frhash2_create(&st_hash_report, 3), FR_SUCC);

    p_st_private->p_st_req = db2_create_request();
    p_st_private->p_st_fragment->p_st_data = bytebuff_creat();
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x53\xd0\x51\x00\x01\x00\x4d\x20\x14\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x41\x00\x05\x21\x0e\x01\x00\x30\xd0\x53\x00\x01\x00\x2a\x24\x14\x00\x00\x00\x00\x20\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x55\x53\x45\x52\x49\x44\x27\x61\x64\x6d\x69\x6e\x69\x73\x74\x72\x61\x74\x6f\x72\x27\xff\x00\x2d\xd0\x53\x00\x01\x00\x27\x24\x14\x00\x00\x00\x00\x1d\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x57\x52\x4b\x53\x54\x4e\x4e\x41\x4d\x45\x27\x57\x69\x6e\x2d\x50\x43\x27\xff\x00\x5f\xd0\x43\x00\x01\x00\x59\x24\x14\x00\x00\x00\x00\x4f\x53\x45\x54\x20\x43\x4c\x49\x45\x4e\x54\x20\x41\x43\x43\x54\x4e\x47\x27\x4a\x43\x43\x30\x32\x31\x30\x30\x57\x69\x6e\x2d\x50\x43\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x61\x64\x6d\x69\x6e\x69\x73\x74\x27\x2c\x58\x27\x30\x30\x27\xff",
                 271);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_EXCSQLSET);

    i_ret = __db2_parse_excsqlset(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_SUCC);
    CU_ASSERT_EQUAL(p_st_private->p_st_req->p_st_command_pre->l_cursor_id, 65);
    CU_ASSERT_STRING_EQUAL(p_st_private->p_st_req->p_st_command_pre->p_st_statement->p_sql,
                           "SET CLIENT USERID'administrator';SET CLIENT WRKSTNNAME'Win-PC';SET CLIENT ACCTNG'JCC02100Win-PC                                administ',X'00'");

    /* 追加数据 */
    bytebuff_add(p_st_private->p_st_fragment->p_st_data,
                 (char *) "\x00\x58\xd0\x51\x00\x01\x00\x52\x20\x0d\x00\x44\x21\x13\xe3\xd6\xd6\xd3\xe2\xc4\xc2\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xd5\xe4\xd3\xd3\xc9\xc4\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\xe2\xe8\xe2\xe2\xc8\xf2\xf0\xf0\x40\x40\x40\x40\x40\x40\x40\x40\x40\x40\x53\x59\x53\x4c\x56\x4c\x30\x31\x00\x02\x00\x05\x21\x16\xf1\x00\x06\x21\x46\x04\x04",
                 89);
    bytebuff_setPosition(p_st_private->p_st_fragment->p_st_data, p_st_private->p_st_fragment->u64_parsed_index);
    db2_get_ddm_cp(p_st_private->p_st_fragment, DB2_FALSE, &i_req_cp, &p_st_private->p_st_req->ui_ddm_len);
    CU_ASSERT_EQUAL(i_req_cp, DRDA_CP_PRPSQLSTT);

    i_ret = __db2_parse_prpsqlstt(p_st_conn, &st_hash_report, p_st_private, DB2_FALSE);

    CU_ASSERT_EQUAL(i_ret, APM_L7_ANALYZE_FAIL);

    frhash2_free(&st_hash_report, list_report_node_free);
    test_db2_destroy_ct(&p_st_conn);

    return;
}

int add_suite__db2_parse_prpsqlstt(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __db2_parse_prpsqlstt()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL ||
        CU_add_test(pSuite, "case5", __case5) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
